var rptType=5
var rpttime=1
var areaid=3501
var secret='2020abc'
var iLng=117.019157
var iLat=25.075648
var iRange=15
var info=Array()
var minz=1
function compare(property){
    return function(a,b){
        var value1 = a[property];
        var value2 = b[property];
        return value1 - value2;
    }
}

// JS`正则表达式`获取地址栏url参数：
 function getUrlParam(name) {
     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); // 构造一个含有目标参数的正则表达式对象
     var r = window.location.search.substr(1).match(reg); // 匹配目标参数
     if (r != null) return unescape(r[2]);
     return null; // 返回参数值
 }
 // 调用方法
areaid = getUrlParam('areaid');

if(areaid=='china'){
	minz=1
}else if(areaid>10000000){
	minz=19
}else if(areaid>100000){
	minz=17
}else if(areaid>1000){
	minz=12
}else if(areaid>1){
	minz=8
}
function getData1(url) {
	var randNum = Math.floor(Math.random() * 1000000000)
	var jiamistr ='areaid=' + areaid + 'randNum=' + randNum + 'rpttime=' + rpttime + 'rptType=' + rptType
	var jiami = $.md5(jiamistr) + secret;
	var sign = $.md5(jiami)
	$.ajax({
		url: url,
		data: {
			rpttime,
			rptType,
			areaid,
			randNum,
			sign
		},
		dataType: 'json',	
		type: 'get',
		success: function(data) {
			console.log(data)
			if(data.code==0){
				iLng=data.data.iLng
				iLat=data.data.iLat	
				// 标题
				$('.header .title').html(`${data.data.rptTitle}`)
				// 人员分类汇总统计(图中上)
				$('.c-top ul').html('')
				data.data.details.forEach(function(item, key) {
					$('.c-top ul').append(`
						<li>
							<div class="star">★</div>
							<div class="text text1">
								<p>${item.className}（人）</p>
								<p>${item.iNum}/${item.itotal}</p>
								<p>应到/在岗</p>
							</div>
						</li>
					`)
				})
				getData6('http://www.xuebanjicai.com:8166/Apps/ws/101/api/screen_data.asmx/getviolationSite')
			}
		}
	});
}


// 人员分类汇总统计(图左上)
function getData2(url) {
	var randNum = Math.floor(Math.random() * 1000000000)
	var jiamistr ='areaid=' + areaid + 'randNum=' + randNum + 'rpttime=' + rpttime + 'rptType=' + rptType
	var jiami = $.md5(jiamistr) + secret;
	var sign = $.md5(jiami)
	var edata = Array()
	var areas = Array()
	var all=Array()
	$.ajax({
		url: url,
		data: {
			rpttime,
			rptType,
			areaid,
			randNum,
			sign
		},
		dataType: 'json',	
		type: 'get',
		success: function(data) {
			if(data.code==0){
				data.data.details.forEach(function(item, key) {
					areas.push(item.className)
					all.push({
						'value':item.iNum,
						'name':item.className
					})
				})
				edata['areas'] = areas
				edata['all'] = all
			}
			echart1(edata)
		}
	});
}


function getData3(url) {
	var randNum = Math.floor(Math.random() * 1000000000)
	var jiamistr ='areaid=' + areaid + 'randNum=' + randNum + 'rpttime=' + rpttime + 'rptType=' + rptType
	var jiami = $.md5(jiamistr) + secret;
	var sign = $.md5(jiami)
	var edata = Array()
	var names = Array()
	var nums = Array()
	var all=Array()
	$.ajax({
		url: url,
		data: {
			rpttime,
			rptType,
			areaid,
			randNum,
			sign
		},
		dataType: 'json',	
		type: 'get',
		success: function(data) {
			if(data.code==0){
				var arr=data.data.sort(compare('iNum'))
				arr.forEach(function(item, key) {
					names.push(item.siteName)
					nums.push(item.iNum)
				})
				// 右下
				edata['names'] = names
				edata['num3'] = nums
			}
			echart3(edata)
		}
	});
}

// 左下
function getData5(url) {
	var randNum = Math.floor(Math.random() * 1000000000)
	var jiamistr ='areaid=' + areaid + 'randNum=' + randNum + 'rpttime=' + rpttime + 'rptType=' + rptType
	var jiami = $.md5(jiamistr) + secret;
	var sign = $.md5(jiami)
	$.ajax({
		url: url,
		data: {
			rpttime,
			rptType,
			areaid,
			randNum,
			sign
		},
		dataType: 'json',	
		type: 'get',
		success: function(data) {
			console.log(data)
			if(data.code==0){
				// 左下
				$('.list').html('')
				data.data.forEach(function(item, key) {
					var zz=Array()
					zz[0]=item.iLng
					zz[1]=item.iLat
					zz[2]=item.siteName
					zz[3]=item.imgurl
					zz[4]=item.supervisor
					zz[5]=item.cTel
					info.push(zz)
					// 左下
					$('.list').append(`
						<li class="clearfix" iLng=${item.iLng} iLat=${item.iLat}>
							<div class="item-l">
								<img src="${item.imgurl}" alt="">
							</div>
							<div class="item-c">
								<p class="p1">${item.siteName}</p>
								<p class="p2">${item.className}</p>
							</div>
							<div class="item-r">
								<p class="p1">检查：${item.supervisor}</p>
								<p class="p2">${item.dDate}</p>
							</div>
						</li>
					`)
				})
			}
		}
	});
}
// 右上
function getData4(url) {
	var randNum = Math.floor(Math.random() * 1000000000)
	var jiamistr ='areaid=' + areaid + 'randNum=' + randNum + 'rpttime=' + rpttime + 'rptType=' + rptType
	var jiami = $.md5(jiamistr) + secret;
	var sign = $.md5(jiami)
	var edata = Array()
	var areas = Array()
	var names = Array()
	var data1 = Array()
	data1[0]= Array()
	data1[1]= Array()
	data1[2]= Array()
	data1[3]= Array()
	$.ajax({
		url: url,
		data: {
			rpttime,
			rptType,
			areaid,
			randNum,
			sign
		},
		dataType: 'json',	
		type: 'get',
		success: function(data) {
			
			if(data.code==0){
				data.data.forEach(function(item, key) {
					names.push(item.time)
					item.details.forEach(function(item1, key1) {
						areas[key1]=(item1.className)
						data1[key1].push(item1.iNum)
					})
				})
				edata['names']=names
				edata['areas']=areas
				edata['data']=data1
			}
			echart2(edata)
		}
	});
}
// 中下
function getData6(url) {
	var randNum = Math.floor(Math.random() * 1000000000)
	var jiamistr ='areaid=' + areaid + 'iLat=' + iLat + 'iLng=' + iLng + 'iRange=' + iRange + 'randNum=' + randNum + 'rpttime=' + rpttime + 'rptType=' + rptType
	var jiami = $.md5(jiamistr) + secret;
	var sign = $.md5(jiami)
	var edata = Array()
	$.ajax({
		url: url,
		data: {
			iLat,
			iLng,
			iRange,
			rpttime,
			rptType,
			areaid,
			randNum,
			sign
		},
		dataType: 'json',	
		type: 'get',
		success: function(data) {
			if(data.code==0){
				data.data.forEach(function(item, key) {
					var zz=Array()
					zz[0]=item.iLng
					zz[1]=item.iLat
					zz[2]=item.siteName
					zz[3]="img/pic.png"
					zz[4]=item.supervisor
					zz[5]=item.cTel
					edata.push(zz)
				})
			}
			showmap(edata)
		},
		error: function(data) {
			console.log(data)
		}
	});
}

